import requests
from bs4 import BeautifulSoup
import os


url = "http://www.usth.edu.cn/info/1150/1506.htm"
urlRoot = "http://www.usth.edu.cn"

response = requests.get(url)
response.encoding = 'utf-8'
html_text = response.text
soup = BeautifulSoup(html_text, 'html.parser')

imgs = soup.findAll("img", {"class": "img_vsb_content"})
imgs = [urlRoot + img["src"] for img in imgs]


FileName = 'tupian'
if not os.path.exists(os.path.join(os.getcwd(), FileName)):     # 新建文件夹   
     print(u'建了一个名字叫做', FileName, u'的文件夹！')
     os.mkdir(os.path.join(os.getcwd(),'tupian'))
else:
    print(u'名字叫做', FileName, u'的文件夹已经存在了！')

for img in imgs:
    r = requests.get(img)
    fpath = os.path.join(FileName, img[-20: ])
    with open(fpath+'.jpg','wb+')as f : # 循环写入图片
        f.write(r.content)


# print(soup)
